package com.ophiux.FeverManagement.aplication.serviceImpl.patient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.FeverManagement.aplication.bean.patient.getPatientInfoListRequest;
import com.ophiux.FeverManagement.aplication.bean.patient.getPatientInfoListResponse;
import com.ophiux.FeverManagement.aplication.service.patient.IGetPatientInfoListService;
import com.ophiux.FeverManagement.domain.entity.RbPatientinfo;
import com.ophiux.FeverManagement.domain.repository.IPatientRepositories;
import com.ophiux.micro.core.application.Result;
import com.ophiux.micro.core.application.ResultEnum;
import com.ophiux.utils.common.ShiftUtils;
@Service
public class GetPatientInfoListServiceImpl implements IGetPatientInfoListService{
	@Autowired
	IPatientRepositories patientRepositories;
	
	@Override
	public Result<List<getPatientInfoListResponse>> getPatientInfoList(getPatientInfoListRequest dto) {
		Result<List<getPatientInfoListResponse>> result = new Result<>();
		List<getPatientInfoListResponse>  responseList = new ArrayList<>();
		if(!dto.isParamValid()) {
			return Result.fail(ResultEnum.requestParamFail);
		}
		try {
			Map patientMap = new HashMap();
			patientMap.put("PATIENT_NAME", dto.getPATIENT_NAME());
			patientMap.put("TEL", dto.getTEL());
			patientMap.put("ID_NO", dto.getID_NO());
			List<RbPatientinfo> rbPatientList = patientRepositories.selectAll(patientMap);
			
			for (RbPatientinfo patient : rbPatientList) {
				getPatientInfoListResponse res = (getPatientInfoListResponse) ShiftUtils
								.objToNewObj(patient, getPatientInfoListResponse.class);
				responseList.add(res);
			}
			result = Result.success(responseList);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.fail("","操作异常");
		}
		return result;
	}

}
